package cn.itcast.bos.web.action.take_delivery;

import java.io.File;
import java.util.UUID;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.itcast.bos.domain.take_delivery.Promotion;
import cn.itcast.bos.web.action.common.BaseAction;

@Namespace("/")
@ParentPackage("json-default")
@Scope("prototype")
@Controller
public class PromotionAction extends BaseAction<Promotion> {

	// 文件的上传，这里也有图片的上传
	private File titleImgFile;
	private String titleImgFileFileName;

	public void setTitleImgFile(File titleImgFile) {
		this.titleImgFile = titleImgFile;
	}

	public void setTitleImgFileFileName(String titleImgFileFileName) {
		this.titleImgFileFileName = titleImgFileFileName;
	}

	@Action(value = "promotion_save", results = { @Result(name = "success", type = "redirect", location = "./pages/take_delivery/promotion.html") })
	public String save() {

		//获得文件的绝对位置
		 String savePath = ServletActionContext.getServletContext().getRealPath("/imgUpload/");
		 //获得文件的相对于项目的路径
		 String saveUrl=ServletActionContext.getRequest().getContextPath()+"/imgUpload/";
		 //生成随机的文件名
		 UUID uuid = UUID.randomUUID();
		 //新文件的名字
		 String randomFileName=uuid+titleImgFileFileName.substring(titleImgFileFileName.lastIndexOf("."));
		 //保存图片
		 
		return SUCCESS;
	}

}
